import logging

from redis import StrictRedis
from datetime import timedelta


# 基类配置
class Config(object):
    # 秘钥
    SECRET_KEY = '\x88\xa7\xe1zZD\x1e\x1c\t$XI\xbd\x1b:\xfe\xee$\x86k\x1e\xdd\xa2%'
    # 调试信息
    DEBUG = True
    # mysql数据库配置信息
    HOSTNAME = '127.0.0.1'
    PORT = '3306'
    DATABASE = 'flask_news_information'
    USERNAME = 'root'
    PASSWORD = 'root'
    DB_URI = "mysql+pymysql://{username}:{password}@{host}:{port}/{db}?charset=utf8mb4".format(username=USERNAME,
                                                                                               password=PASSWORD,
                                                                                               host=HOSTNAME, port=PORT,
                                                                                               db=DATABASE)
    SQLALCHEMY_DATABASE_URI = DB_URI
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True # 每当改变数据库模型对象的内容(属性，例如改年龄，性别等)不用手动的写db.session.commit()会自动提交
    # redis数据库配置信息
    REDIS_HOST = '127.0.0.1'
    REDIST_PORT = 6379
    # session配置信息
    SESSION_TYPE = 'redis'  # 设置session存储类型
    SESSION_REDIS = StrictRedis(host=REDIS_HOST, port=REDIST_PORT)  # 指定session存储的redis服务器
    SESSION_USE_SIGNER = True  # 设置签名存储
    PERMANENT_SESSION_LIFETIME = timedelta(days=2)  # session的过期时间
    # 默认日志级别
    LEVEL_NAME = logging.ERROR


# 开发环境配置
class DevelopConfig(Config):
    DEBUG = True


# 生产环境配置
class ProductConfig(Config):
    DEBUG = False
    LEVEL_NAME = logging.ERROR


# 测试环境配置
class TestConfig(Config):
    pass


# 统一接口入口
config_dict = {
    "develop": DevelopConfig,
    "product": ProductConfig,
    "test": TestConfig
}
